<script setup lang="ts">
import { useUserInfoStore } from '@/store/userInfo'

const router = useRouter()
const userInfoStore = useUserInfoStore()

function handleViewProtocol(type: string) {
  router.push({
    name: 'protocol',
    params: { type },
  })
}

function handleTapLogout() {
  uni.showModal({
    title: '确定要退出登录吗？',
    confirmColor: '#4999F7',
    success: (result) => {
      if (result.confirm) {
        userInfoStore.$reset()
        router.replaceAll('index')
      }
    },
  })
}
</script>

<template>
  <Spacer height="40" />
  <view class="overflow-hidden rounded-10rpx bg-white">
    <ListCell label="用户协议" @tap="handleViewProtocol('用户协议')">
      <view class="h-120rpx flex items-center">
        <image class="ml-8rpx h-23rpx w-13rpx" src="@/static/images/cheveron_right.png" />
      </view>
    </ListCell>
    <Divider width="623" color="#E6E6E6" />
    <ListCell label="隐私政策" @tap="handleViewProtocol('隐私政策')">
      <view class="h-120rpx flex items-center">
        <image class="ml-8rpx h-23rpx w-13rpx" src="@/static/images/cheveron_right.png" />
      </view>
    </ListCell>
    <Divider width="623" color="#E6E6E6" />
    <ListCell label="免责协议" @tap="handleViewProtocol('免责协议')">
      <view class="h-120rpx flex items-center">
        <image class="ml-8rpx h-23rpx w-13rpx" src="@/static/images/cheveron_right.png" />
      </view>
    </ListCell>
    <Divider width="623" color="#E6E6E6" />
    <ListCell label="退出登录" @tap="handleTapLogout">
      <view class="h-120rpx flex items-center">
        <image class="ml-8rpx h-23rpx w-13rpx" src="@/static/images/cheveron_right.png" />
      </view>
    </ListCell>
  </view>
</template>

<route lang="yaml">
name: 'settings'
style:
  navigationBarTitleText: '设置'
</route>
